<template>
  <component
    :is="$attrs.component || $attrs.render"
    :value="currentValue"
    v-bind="$attrs"
    @input="handleInputEvent"
  />
</template>

<script lang="ts">
import { defineComponent, PropType, ref, watch } from "vue";

type ValueType = string | boolean | number | object | any[];

export default defineComponent({
  name: "Customer",
  props: {
    value: {
      type: [String, Boolean, Number, Object, Array] as PropType<ValueType>,
      default: "",
    },
  },
  emits: {
    input: (payload: ValueType) => typeof payload !== "undefined", // More precise validation
  },
  setup(props, { emit }) {
    const currentValue = ref<ValueType>(props.value);

    watch(
      () => props.value,
      (val) => {
        currentValue.value = val;
      },
      { deep: true }
    );

    const handleInputEvent = (val: ValueType) => {
      emit("input", val);
    };

    return {
      currentValue,
      handleInputEvent,
    };
  },
});
</script>

<style lang="scss" scoped></style>
